package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.StoTransportPlanPickVO;
import com.yunxi.sto.pojo.StoTransportPlanQueryVO;
import com.yunxi.sto.pojo.StoTransportPlanVO;
import com.yunxi.sto.service.StoTransportPlanDubboService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 运输计划单 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-05-23
 */
@RestController
@RequestMapping("/admin/stoTransportPlan")
@Api(tags = "sto:transportPlan", description = "运输计划单接口")
public class StoTransportPlanController {
 private static final Logger logger = LoggerFactory.getLogger(StoTransportPlanController.class);

 @Autowired
 StoTransportPlanDubboService stoTransportPlanDubboService;

 @GetMapping("/page")
 @ApiOperation(value = "查询分页")
 public ApiResult page(StoTransportPlanQueryVO stoTransportPlanQueryVO, @RequestParam(required = true) Integer pageNum, @RequestParam(required = true) Integer pageSize) throws Exception {
  return ResponseUtil.ok(stoTransportPlanDubboService.findPageByVO(stoTransportPlanQueryVO, pageNum, pageSize));
 }

 @GetMapping("/selfPage")
 @ApiOperation(value = "自提车辆查询分页")
 @ApiImplicitParams({
         @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
         @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
 })
 public ApiResult selfPage(StoTransportPlanQueryVO stoTransportPlanQueryVO,Integer pageNum,Integer pageSize) throws Exception {
  stoTransportPlanQueryVO.setIsPickSelf(1);
  return ResponseUtil.ok(stoTransportPlanDubboService.findPageByVO(stoTransportPlanQueryVO, pageNum, pageSize));
 }

 @PostMapping("/pickVehicle")
 @ApiOperation(value = "提车")
 public ApiResult pickVehicle(@RequestBody StoTransportPlanPickVO stoTransportPlanPickVO) throws Exception {
  stoTransportPlanDubboService.pickVehicle(stoTransportPlanPickVO);
  return ResponseUtil.ok("success");
 }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 public ApiResult load(StoTransportPlanVO stoTransportPlanVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(stoTransportPlanDubboService.getById(stoTransportPlanVO.getTransportPlanId()));
 }

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody StoTransportPlanVO stoTransportPlanVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoTransportPlanDubboService.saveOrUpdate(stoTransportPlanVO);
  return ResponseUtil.ok("success");
 }

 @PostMapping("/carriageRoute")
 @ApiOperation(value = "选择运输路线")
 public ApiResult route(@RequestParam(value = "routeCode")@ApiParam(value = "运输路线代码",required = true) String routeCode,
                        @RequestParam(value = "transportPlanId")@ApiParam(value = "运输计划主键id",required = true) String transportPlanId) throws Exception {
  stoTransportPlanDubboService.route(transportPlanId,routeCode);
  return ResponseUtil.ok("success");
 }

 @GetMapping("/carrierList")
 @ApiOperation(value = "获取承运商列表")
 public ApiResult route(@RequestParam(value = "routeCode")@ApiParam(value = "运输路线代码",required = true) String routeCode) throws Exception {
  return ResponseUtil.ok(stoTransportPlanDubboService.carrierList(routeCode));
 }

 @PostMapping("/carrier")
 @ApiOperation(value = "选择承运商")
 public ApiResult carrier(@RequestParam(value = "carrierCode")@ApiParam(value = "承运商代码",required = true) String carrierCode,
                          @RequestParam(value = "transportPlanId")@ApiParam(value = "运输计划主键id",required = true)String transportPlanId) throws Exception {
  stoTransportPlanDubboService.carrier(transportPlanId,carrierCode);
  return ResponseUtil.ok("success");
 }

 @PostMapping("/cancel")
 @ApiOperation(value = "取消计划")
 public ApiResult cancel(@RequestParam(value = "list")@ApiParam(value = "主键id集合") List<String> list) throws Exception {
  stoTransportPlanDubboService.removeById(list);
  return ResponseUtil.ok("success");
 }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(stoTransportPlanDubboService.findMapByList(params));
}*/
}
